<?php
class Userinfo extends CI_Controller {
	private $user_ifno;
	public function __construct() {
		parent::__construct ();
		
		// 登录校验
		$this->common->check_login_mobile ();
		
		// user_model
		$this->load->model ( 'user_model' );
		$this->user_info = $this->user_model->get_user_info_id ( $_SESSION ['mobile'] ['id'] ); // $_SESSION['user'];//1;
	}
	
	/**
	 * 修改个人信息
	 */
	public function index() {
		$this->load->helper ( 'form' );
		
		$data ['user'] = $this->user_info;
		
		$data ['left'] = $this->load->view ( 'mobile/left', '', TRUE );
		
		$data ['foot'] = $this->load->view ( 'mobile/foot', '', TRUE );
		
		$this->load->view ( 'mobile/userinfo', $data );
	}
	
	/**
	 * 个人信息提交
	 */
	public function info_post() {
		if (empty ( $_POST )) {
			exit ( $this->common->alert_msg_goback ( '参数错误' ) );
		}
		$id = $this->user_info ['id'];
		// 二级密码校验
		$check = $this->user->check_spwd ( $id, md5 ( $_POST ['spwd'] ) );
		
		if (empty ( $check )) {
			exit ( $this->common->alert_msg_goback ( '二级密码错误' ) );
		}
		
		$result = $this->user->update_userinfo ( $id );
		
		if ($result) {
			exit ( $this->common->alert_msg_url ( '更新成功', site_url ( 'mobile/userinfo' ) ) );
		} else {
			exit ( $this->common->alert_msg_goback ( '更新失败' ) );
		}
	}
}